package top.huhuiyu.spirngboot2.total.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.huhuiyu.spirngboot2.total.base.BaseDataResult;
import top.huhuiyu.spirngboot2.total.base.BasePageResult;
import top.huhuiyu.spirngboot2.total.base.BaseResult;
import top.huhuiyu.spirngboot2.total.base.PageBean;
import top.huhuiyu.spirngboot2.total.entity.TbNews;
import top.huhuiyu.spirngboot2.total.service.NewsService;

import java.util.List;

@RestController
@RequestMapping("/news")
public class NewsController {
    @Autowired
    private NewsService newsService;

    @GetMapping
    public BasePageResult<List<TbNews>> query(PageBean page, TbNews tbNews) {
        return newsService.query(page, tbNews);
    }

    @GetMapping("/{id}")
    public BaseDataResult<TbNews> queryById(@PathVariable("id") Integer id) {
        return newsService.queryByKey(id);
    }

    @PostMapping
    public BaseResult add(@RequestBody TbNews tbNews) {
        return newsService.add(tbNews);
    }

    @PutMapping
    public BaseResult update(@RequestBody TbNews tbNews) {
        return newsService.update(tbNews);
    }

    @DeleteMapping("/{id}")
    public BaseResult delete(@PathVariable("id") Integer id) {
        return newsService.delete(id);
    }

}
